import pygame # 导入模块
from pygame.locals import *
pygame.init()  # 初始化模块
screen = pygame.display.set_mode((800,600))  # 创建一个Surface对象窗口
pygame.display.set_caption("Pong游戏")  # 设置标题
keep_going = True  # 循环标志
BLACK = (0,0,0) # 黑色
# 挡板
WHITE = (255,255,255)
paddle_width = 200 # 挡板宽度
paddle_height = 25 # 挡板高度
paddle_x = 300 # 挡板left属性
paddle_y = 550 # 挡板top属性

while keep_going:
    for event in pygame.event.get():
        if event.type == QUIT:
            keep_going = False
    screen.fill(BLACK) # 填充背景
    # 绘制挡板
    paddle_x = pygame.mouse.get_pos()[0]
    paddle_x -= paddle_width/2
    pygame.draw.rect(screen,WHITE,(paddle_x,paddle_y,paddle_width,paddle_height))
    pygame.display.flip()

pygame.quit()

WHITE = (255,255,255)
paddle_width = 200 # 挡板宽度
paddle_height = 25 # 挡板高度
paddle_x = 300 # 挡板left属性
paddle_y = 550 # 挡板top属性
pygame.draw.rect(Surface,color,Rect,width=0),Rect(left,top,width,height)
pygame.draw.rect(screen,WHITE,(paddle_x,paddle_y,paddle_width,paddle_height))
pygame.mouse.get_pos()
x = pygame.mouse.get_pos()[0]  # 索引0代表鼠标的x坐标
y = pygame.mouse.get_pos()[1]  # 索引1代表鼠标的y坐标
paddle_x = pygame.mouse.get_pos()[0]
paddle_x -= paddle_width/2
paddle_x = pygame.mouse.get_pos()[0]
paddle_x - paddle_width/2
paddle_x = paddle_x - paddle_width/2
import pygame # 导入模块
from pygame.locals import *
pygame.init()  # 初始化模块
screen = pygame.display.set_mode((800,600))  # 创建一个Surface对象窗口
pygame.display.set_caption("Pong游戏")  # 设置标题
keep_going = True  # 循环标志
BLACK = (0,0,0)
pygame.display.set_caption("Pong游戏")
while keep_going:
    for event in pygame.event.get():
        if event.type == QUIT:
            keep_going = False


import pygame # 导入模块
from pygame.locals import *
pygame.init()  # 初始化模块
screen = pygame.display.set_mode((800,600))  # 创建一个Surface对象窗口
pygame.display.set_caption("Pong游戏")  # 设置标题
keep_going = True  # 循环标志
BLACK = (0,0,0)
clock = pygame.time.Clock()
# 挡板
WHITE = (255,255,255)
paddle_width = 200 # 挡板宽度
paddle_height = 25 # 挡板高度
paddle_x = 300    # 挡板left属性
paddle_y = 550    # 挡板top属性
# 笑脸图片
pic = pygame.image.load("Smile.bmp").convert_alpha()
colorkey = pic.get_at((0,0))
pic.set_colorkey(colorkey)
# 速度和位置
speedx = 5
speedy = 5
pic_x = 0
pic_y = 0

while keep_going:
    for event in pygame.event.get():
        if event.type == QUIT:
            keep_going = False

    pic_x += speedx
    pic_y += speedy
    # 墙壁碰撞检测
    if pic_x <= 0 or pic_x + pic.get_width() >= 800:
        speedx = - speedx

    if pic_y <= 0 or pic_y + pic.get_height() >= 600:
        speedy = -speedy
    screen.fill(BLACK) # 填充背景
    # 绘制挡板
    paddle_x = pygame.mouse.get_pos()[0]
    paddle_x -= paddle_width/2
    pygame.draw.rect(screen,WHITE,(paddle_x,paddle_y,paddle_width,paddle_height))

    # 绘制笑脸图片
    screen.blit(pic,(pic_x,pic_y))

    pygame.display.flip()
    clock.tick(60) # 设置帧速率

pygame.quit()